feat!: Introduce new summary section for data metrics#47
feat!: Introduce new summary section for data metrics#47Moritz Potthoff (MoritzPotthoffQC) wants to merge 26 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #47 +/- ##
===========================================
- Coverage 100.00% 99.73% -0.27%
===========================================
Files 14 14
Lines 1052 1141 +89
===========================================
+ Hits 1052 1138 +86
- Misses 0 3 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends Diffly’s summary reporting to distinguish change metrics (computed over deltas) from data inspection metrics (describing left/right datasets), and renders the latter in a new dedicated “Data Inspection” section while also separating them in the JSON schema.
Changes:
- Add
Metric.kind("change"vs"data") and mark theNull%preset as a"data"metric. - Split per-column metric outputs into
metricsvsdata_metricsin the summary JSON, and render"data"metrics in a new “Data Inspection” section. - Update summary tests and regenerate pretty-output fixtures to reflect the new section/layout.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| diffly/metrics/_common.py | Adds Metric.kind to classify metrics by rendering section. |
| diffly/metrics/data.py | Marks Null% preset as a "data" metric. |
| diffly/summary.py | Routes metric labels into change vs data lists; adds “Data Inspection” rendering and JSON schema changes. |
| tests/summary/test_summary.py | Adds coverage for metrics vs data_metrics JSON routing; updates expected JSON shape. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_True_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_True_perfect_False_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_True_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_True_sample_pk_True.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_True_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
| tests/summary/fixtures/metrics_null_fraction/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_False_sample_pk_False.txt | Updates fixture output to move Null% into “Data Inspection”. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
EgeKaraismailogluQC
left a comment
There was a problem hiding this comment.
Thank you Moritz Potthoff (@MoritzPotthoffQC)! In general I am happy with the layout. I added a few comments. In addition to those, I think it would be nice to have at least one summary fixture where we render two or more data metrics rather than just one, just to see what that looks like (maybe I missed it?).
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
EgeKaraismailogluQC I made quite a few changes since your review. I'd appreciate another look. Let me know if you want to chat about this! |
EgeKaraismailogluQC
left a comment
There was a problem hiding this comment.
Thank you for working on this Moritz Potthoff (@MoritzPotthoffQC), looks very nice! Just a few cosmetic comments. Let's also add ! to the PR title to mark it as breaking.
| return v | ||
| # Infer the metric family from the callable's arity: a single-argument | ||
| # callable describes one side (data), two arguments describe a change. | ||
| if len(inspect.signature(v).parameters) >= 2: |
There was a problem hiding this comment.
Why not:
| if len(inspect.signature(v).parameters) >= 2: | |
| if isinstance(v, ChangeMetricFn): |
Also, how about being a bit defensive here and do:
elif isinstance(v, DataMetricFn):
...
else:
raiseso that the signature issue is easier to understand for the user?
There was a problem hiding this comment.
if isinstance(v, ChangeMetricFn): does not work as ChangeMetricFn is only as Callable type alias. But I now extended this to much more explicitly check the positional args in the methods that are provided.
| @@ -963,20 +1041,50 @@ def select_columns(selector: cs.Selector) -> set[str]: | |||
| for label, metric in metrics.items() | |||
| for column in sorted(metric_to_columns[label]) | |||
| ] | |||
| row = joined.select(agg_exprs).collect().row(0, named=True) | |||
| for label, columns in metric_to_columns.items(): | |||
| for column in columns: | |||
|
|
|||
| row = comp.joined(lazy=True).select(agg_exprs).collect().row(0, named=True) | |||
| out: dict[str, dict[str, Any]] = { | |||
| c: {} for c in set().union(*metric_to_columns.values()) | |||
| } | |||
| for label in metrics: | |||
| for column in metric_to_columns[label]: | |||
| out[column][label] = row[f"{label}__{column}"] | |||
| return out | |||
There was a problem hiding this comment.
Am I missing something or is this part just a "shallow" refactor?
There was a problem hiding this comment.
You're right 👍 I refactored this a bit while I was working on this method (what is now _compute_data_metrics used to be entangled with this). I think it's easier to read this way, but we can also revert if you'd like
| formatter=lambda value: f"{round(value * 100, 2)}%", | ||
| delta_formatter=lambda value: f"{round(value * 100, 2)}", |
There was a problem hiding this comment.
Should we use these as the default formatter for DataMetric?
There was a problem hiding this comment.
I think the percentage output is rather specific and would not fit for other data metrics I could imagine (e.g., mean). For floats, we already apply default formatting if no formatter is provided.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Motivation
See this discussion: We want to display
datametrics in their own section in the summary.Changes
Data Inspectionthat gets all the data metrics